package com.mybase.app.fourBase;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * Created by happy_000 on 2014/12/10.
 */
public class ProviderActivity extends Activity {

    private Button queryButton = null;
    private Button insertButton = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.main);
        queryButton =  new Button(this);
        insertButton = new Button(this);
        queryButton.setOnClickListener(new QueryListener());
        insertButton.setOnClickListener(new InsertListener());
        System.out.println(getContentResolver().getType(ProviderData.UserTableMetaData.CONTENT_URI));
    }

    class InsertListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            // TODOAuto-generated method stub
            ContentValues values = new ContentValues();
            values.put(ProviderData.UserTableMetaData.USER_NAME,
                    "michal");
            Uri uri = getContentResolver()
                    .insert(
                            ProviderData.UserTableMetaData.CONTENT_URI,
                            values);
            System.out.println("uri--->" + uri.toString());
        }

    }

    class QueryListener implements View.OnClickListener {
        public void onClick(View v) {
            Cursor c = getContentResolver().query(
                    ProviderData.UserTableMetaData.CONTENT_URI, null,
                    null, null, null);
            while (c.moveToNext()) {
                System.out.println(c.getString(c.getColumnIndex("username")));

            }

        }
    }
}